package com.ldq.imooc.basics.io;

import java.io.*;
import java.util.ArrayList;

/**
 * @Author : 李道泉
 * @Description :
 * @Date : 2018/4/17 15:44
 * @Modified by :
 */
public class ObjectSeriaDemo {

    public static void main(String[] args) throws Exception {

        String file = "demo/obj.bat";
        Student stu1 = new Student("1",18,"张三丰");
        objSeri(file,stu1);
        unObjSeri(file);
    }

    /**
      * @Author : 李道泉
      * @Description : 对象序列化
      * @Date 2018/4/17 16:21
      * @Modified by :
      */
    public static void objSeri(String file,Student stu) throws Exception {

        ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(file));
        oos.writeObject(stu);
        oos.flush();
        oos.close();
    }

    /**
      * @Author : 李道泉
      * @Description : 反序列化
      * @Date 2018/4/17 16:21
      * @Modified by :
      */
    public static void unObjSeri(String file) throws Exception {

        ObjectInputStream ois = new ObjectInputStream(new FileInputStream(file));
        Student stu2 = (Student) ois.readObject();
        System.out.println(stu2);
        ois.close();
    }
}
